﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;

namespace Chenxin.Lib.Hr.DAL
{
    /// <summary>
    /// 数据访问类Struct_AttendanceCircle。
    /// </summary>
    public class Struct_AttendanceCircle
    {
        public Struct_AttendanceCircle()
        { }
        #region  成员方法


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static void Add(Chenxin.Lib.Hr.Entity.Struct_AttendanceCircle model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Struct_AttendanceCircle(");
            strSql.Append("RecordId,StartMonthFlg,StartDate,EndMonthFlg,EndDate,StartTime,EndTime,LateTimeOut,OverTimeStartTime,UpdateUser,UpdateTime)");

            strSql.Append(" values (");
            strSql.Append("@RecordId,@StartMonthFlg,@StartDate,@EndMonthFlg,@EndDate,@StartTime,@EndTime,@LateTimeOut,@OverTimeStartTime,@UpdateUser,@UpdateTime)");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, model.RecordId);
            db.AddInParameter(dbCommand, "StartMonthFlg", DbType.AnsiString, model.StartMonthFlg);
            db.AddInParameter(dbCommand, "StartDate", DbType.Int32, model.StartDate);
            db.AddInParameter(dbCommand, "EndMonthFlg", DbType.AnsiString, model.EndMonthFlg);
            db.AddInParameter(dbCommand, "EndDate", DbType.Int32, model.EndDate);
            db.AddInParameter(dbCommand, "StartTime", DbType.DateTime, model.StartTime);
            db.AddInParameter(dbCommand, "EndTime", DbType.DateTime, model.EndTime);
            db.AddInParameter(dbCommand, "LateTimeOut", DbType.DateTime, model.LateTimeOut);
            db.AddInParameter(dbCommand, "OverTimeStartTime", DbType.DateTime, model.OverTimeStartTime);
            db.AddInParameter(dbCommand, "UpdateUser", DbType.Guid, model.UpdateUser);
            db.AddInParameter(dbCommand, "UpdateTime", DbType.DateTime, model.UpdateTime);
            db.ExecuteNonQuery(dbCommand);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static void Update(Chenxin.Lib.Hr.Entity.Struct_AttendanceCircle model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Struct_AttendanceCircle set ");
            strSql.Append("StartMonthFlg=@StartMonthFlg,");
            strSql.Append("StartDate=@StartDate,");
            strSql.Append("EndMonthFlg=@EndMonthFlg,");
            strSql.Append("EndDate=@EndDate,");
            strSql.Append("StartTime=@StartTime,");
            strSql.Append("EndTime=@EndTime,");
            strSql.Append("LateTimeOut=@LateTimeOut,");
            strSql.Append("OverTimeStartTime=@OverTimeStartTime,");
            strSql.Append("UpdateUser=@UpdateUser,");
            strSql.Append("UpdateTime=@UpdateTime");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, model.RecordId);
            db.AddInParameter(dbCommand, "StartMonthFlg", DbType.AnsiString, model.StartMonthFlg);
            db.AddInParameter(dbCommand, "StartDate", DbType.Int32, model.StartDate);
            db.AddInParameter(dbCommand, "EndMonthFlg", DbType.AnsiString, model.EndMonthFlg);
            db.AddInParameter(dbCommand, "EndDate", DbType.Int32, model.EndDate);
            db.AddInParameter(dbCommand, "StartTime", DbType.DateTime, model.StartTime);
            db.AddInParameter(dbCommand, "EndTime", DbType.DateTime, model.EndTime);
            db.AddInParameter(dbCommand, "LateTimeOut", DbType.DateTime, model.LateTimeOut);
            db.AddInParameter(dbCommand, "OverTimeStartTime", DbType.DateTime, model.OverTimeStartTime);
            db.AddInParameter(dbCommand, "UpdateUser", DbType.Guid, model.UpdateUser);
            db.AddInParameter(dbCommand, "UpdateTime", DbType.DateTime, model.UpdateTime);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static void Delete(Guid RecordId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Struct_AttendanceCircle ");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Chenxin.Lib.Hr.Entity.Struct_AttendanceCircle GetModel()
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,StartMonthFlg,StartDate,EndMonthFlg,EndDate,StartTime,EndTime,LateTimeOut,OverTimeStartTime,UpdateUser,UpdateTime from Struct_AttendanceCircle ");
            //strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Main_Search");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            //db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            Chenxin.Lib.Hr.Entity.Struct_AttendanceCircle model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return model;
        }

        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public static Chenxin.Lib.Hr.Entity.Struct_AttendanceCircle ReaderBind(IDataReader dataReader)
        {
            Chenxin.Lib.Hr.Entity.Struct_AttendanceCircle model = new Chenxin.Lib.Hr.Entity.Struct_AttendanceCircle();
            object ojb;
            ojb = dataReader["RecordId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.RecordId = new Guid(ojb.ToString());
            }
            model.StartMonthFlg = dataReader["StartMonthFlg"].ToString();
            ojb = dataReader["StartDate"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.StartDate = (int)ojb;
            }
            model.EndMonthFlg = dataReader["EndMonthFlg"].ToString();
            ojb = dataReader["EndDate"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EndDate = (int)ojb;
            }
            ojb = dataReader["StartTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.StartTime = (DateTime)ojb;
            }
            ojb = dataReader["EndTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EndTime = (DateTime)ojb;
            }
            ojb = dataReader["LateTimeOut"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.LateTimeOut = (DateTime)ojb;
            }
            ojb = dataReader["OverTimeStartTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.OverTimeStartTime = (DateTime)ojb;
            }
            ojb = dataReader["UpdateUser"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UpdateUser = new Guid(ojb.ToString());
            }
            ojb = dataReader["UpdateTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UpdateTime = (DateTime)ojb;
            }
            return model;
        }

        #endregion  成员方法
    }
}

